package br.com.io.streams;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class CopiaViaStream {
	public static void main(String[] args) {
		String barra = File.separator;
		StringBuilder sb = new StringBuilder();
		File foolder = new File("stream"+barra+"FileOutPut");
		foolder.mkdir();
		
		sb.append(true);
		sb.append("\nLinha1\nlinha2\nlinha3\nlinha4\nlinha5");
		sb.append(2342342);
		
		
		try {
			OutputStream os_cria = new FileOutputStream("stream"+barra+"FileOutPut"+barra+"arquivoOrigem.txt");
			os_cria.write(sb.toString().getBytes());
			os_cria.write(new Integer(99999).byteValue());
			os_cria.close();
			
			InputStream isOrigem   = new FileInputStream("stream"+barra+"FileOutPut"+barra+"arquivoOrigem.txt");
			OutputStream osDestino = new FileOutputStream("stream"+barra+"FileOutPut"+barra+"arquivoDestino.txt");
			int vByte=-1, i=0;
			byte[] arrayRead = new byte[1000]; 
			while ((vByte = isOrigem.read()) != -1){
				osDestino.write(vByte);
		
				arrayRead[i++] = (byte)vByte;
			}
			
			System.out.println(new String(arrayRead));
			isOrigem.close();
			osDestino.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}
}
